* Preparations

There are some preparations you should take care of, when using Emacs Org Agenda.

** Number of days to display in agenda view

You can set the number of days as follows in your ~.init.el~ file:

#+BEGIN_SRC elisp
(setq org-agenda-span 36)
#+END_SRC

** Setting the starting day of a week

This will change how a week is displayed. I prefer the week to start on Monday, instead of Sunday:

#+BEGIN_SRC elisp
(setq org-agenda-start-on-weekday 1)
#+END_SRC

** Logical order of year/month/day or day/month/year instead of mixed up month/day/year order

Yeah, well, that makes no sense, so lets get it corrected:

#+BEGIN_SRC elisp
(setq european-calendar-style t)
(setq calendar-date-style 'european)
#+END_SRC

** Define your own time span functions

This is useful for more powerful scheduling. You will be able to make use of these functions in your Org-mode files.

The order of arguments to the function changes, depending on the calendar style. If ~european-calendar-style~ is not ~nil~, then the order will be:

1. day1
2. month1
3. year1
4. day2
5. month2
6. year2
7. dayname

If ~european-calendar-style~ is ~nil~, the order will be:

1. month1
2. day1
3. year1
4. month2
5. day2
6. year2
7. dayname

I assume European calendar style here:

#+BEGIN_SRC elisp
;; &%%(diary-schedule 22 4 2003 1 8 2003 2) 18:00 History
(defun diary-schedule (d1 m1 y1 d2 m2 y2 dayname)
  "This procedure defines the format for diary schedule entries.
Order of the parameters is M1, D1, Y1, M2, D2, Y2  DAYNAME if
`european-calendar-style' is nil, and D1, M1, Y1, D2, M2, Y2 if
`european-calendar-style' is t.
Entry does not apply on a history."
  (let ((date1
         (calendar-absolute-from-gregorian
          (if (or european-calendar-style (eq calendar-date-style 'european))
              (list d1 m1 y1)
              (list m1 d1 y1))))
        (date2
         (calendar-absolute-from-gregorian
          (if (or european-calendar-style (eq calendar-date-style 'european))
              (list d2 m2 y2)
              (list m2 d2 y2))))
        (d (calendar-absolute-from-gregorian date)))
    (if (and (<= date1 d)
             (<= d date2)
             (= (calendar-day-of-week date) dayname)
             (not (check-calendar-holidays date)))
        entry)))
#+END_SRC

#+BEGIN_SRC elisp
;; &%%(diary-countdown 22 4 2003 15) Conference deadline
(defun diary-countdown (d1 m1 y1 n)
  "Reminder during the previous n days to the date.  Order of
parameters is M1, D1, Y1, N if `european-calendar-style' is nil,
and D1, M1, Y1, N otherwise."
  (diary-remind
    '(diary-date m1 d1 y1)
    (let
      (value)
      (dotimes
        (number n value)
        (setq value (cons number value))))))
#+END_SRC
